-
Notifications
You must be signed in to change notification settings - Fork 689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clickable URLs #968
Merged
Clickable URLs #968
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Closed
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #29
This adds support for clickable URLs. This initial PR focuses on minimal URL support. There are obvious features which are not yet supported: OSC 8, links requiring keyboard modifiers, additional link actions (explained later), fully configurable links, etc.
This PR only adds support for URLs that match the default regular expression used by Alacritty, which matches various hyperlink URLs and opens them in the default system application. However, the implementation is built to support generic
regex => action
configurations, known as "links." These "links" are not yet configurable in the configuration file, but the base structure is there and everything is built on them.The links system allows a user to configure (1) a regular expression to match (2) an action to execute (i.e. "system open") and (3) conditions to make the link active (i.e. hover). A default link is configured for typical network URLs to open with the system on hover.
Demo
CleanShot.2023-11-29.at.15.45.40.mp4
Terminal Interaction
The primary interaction I could think of was with mouse reporting. If mouse reporting is active, links also can't be activated. If you hold "shift" (to escape mouse reporting capture), then links can be activated even with mouse reporting enabled. The "shift" behavior isn't new to this PR, that's been configurable with
mouse-shift-capture
for some time.Otherwise, links work on both the primary and alternate screen.
Implementation
The implementation uses the Oniguruma regex engine under the hood. We run the regular expression matching twice (once in the GUI thread, once in the renderer thread) because they may have a different view of the viewport state.
The GUI thread checks for link matching whenever the cursor moves and changes viewport cells (i.e. not every pixel, but every cell). This latter detail helps limit the CPU spike when moving the cursor around. In general, the cursor isn't moving much over the terminal window so I don't think this will matter much.
The renderer thread checks for link matching whenever cells are updated, but only evaluates links against the current viewport and only if their highlight conditions are met (hover state, etc.). For the default URL link, this has a minimal impact but in the future when links are configurable, it's probably possible to configure a pathological case here.
Future Work: